/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.edmo.fastener.jms;

import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

/**
 *
 * @author obelog
 */
public class OrderSender {
    	@Autowired
	private JmsTemplate jmsTemplate;
	
	public void sendOrder(final Order order){
		jmsTemplate.send(
		new MessageCreator() {
	      public Message createMessage(Session session) throws JMSException {
	           MapMessage mapMessage = session.createMapMessage();
	           mapMessage.setString("filePath", order.getFilePath());
                   mapMessage.setString("fileName", order.getFileName());
                   mapMessage.setString("orderId", order.getOrderId());
	           return mapMessage;
	      }
	    }
		);
		System.out.println("Order sent - path: "+ order.getFilePath());
	}
}
